using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;

[RequireComponent(typeof(MeshRenderer))]
public class CarPartController : MonoBehaviour
{
    private MeshRenderer m_renderer;
    private Material[] m_materials;
    private static int alphaId = Shader.PropertyToID("_Alpha");
    private void Awake()
    {
        m_renderer = GetComponent<MeshRenderer>();
        //实例化材质
        m_materials = m_renderer.materials;
    }

    [LuaCallCSharp]
    public void controlAlpha(float targetAlpha)
    {
        foreach (var mat in m_materials)
        {
            mat.SetFloat(alphaId,targetAlpha);
        }   
    }

    private void OnDestroy()
    {
        foreach (var mat in m_materials)
        {
            Destroy(mat);
        }   
    }
}

